<template>
  <div>
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clear"
    >
      <template #btns>
        <el-button
          v-if="meta.indexOf('MemberExport') > -1"
          type="primary"
          :loading="exLoading"
          @click="handleEx"
          >{{ $t("message.daochu") }}</el-button
        >
      </template>
    </QueryForm>
    <div class="doumee-table-buttons">
      <el-button
        v-if="meta.indexOf('MemberRegist') > -1"
        type="primary"
        @click="memberAdd()"
        >{{ $t("message.xzhy2") }}</el-button
      >
      <el-button
        v-if="meta.indexOf('VipAddBtn') > -1"
        type="primary"
        @click="toVipAdd"
        >{{ $t("message.hykk") }}</el-button
      >
      <el-button
        v-if="meta.indexOf('vipRechargeBtn') > -1"
        type="primary"
        @click="memberRecharge"
        >{{ $t("message.hycz") }}</el-button
      >
      <el-button
        v-if="meta.indexOf('MemberTagBind') > -1"
        @click="handleAddTag"
        >{{ $t("message.jbq") }}</el-button
      >
      <el-button
        v-if="meta.indexOf('MemberBatchInsert') > -1"
        v-preventReClick
        @click="inBatch"
        >{{ $t("message.hypldr") }}</el-button
      >
      <el-button
        v-if="meta.indexOf('importMemberMeals') > -1"
        v-preventReClick
        @click="isShowb = true"
        >{{ $t("message.tcpldr") }}</el-button
      >
      <div v-if="tjList && tjList.length > 0" class="total_wrapb">
        <div class="first_item">{{ $t("message.bcsxhj") }}</div>
        <div v-for="(item, i) in tjList" :key="i" class="item_list">
          <span class="key"> {{ item.name }}：</span>
          <span class="price">{{ item.money || 0 }}</span>
        </div>
        <el-tooltip effect="dark" placement="left">
          <div class="df_ac">
            <img style="width: 16px" src="@/assets/icon/question.png" />
            {{ $t("message.jesm") }}
          </div>
          <div slot="content" v-html="smTip" />
        </el-tooltip>
      </div>
    </div>
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table doumee-element-tableb"
      @selection-change="handleSelectionChange"
    >
      <el-table-column align="center" type="selection" width="55" />
      <el-table-column
        :label="$t('message.memberInfo')"
        min-width="240"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <span
            v-if="meta.indexOf('GetMemberInfo') > -1"
            class="primaryColor pointer"
            @click="toshowDetail(scope.row.id)"
            >{{
              scope.row.nickName +
              "-" +
              scope.row.phone +
              "-" +
              scope.row.number
            }}</span
          >
          <span v-else>{{
            scope.row.nickName + "-" + scope.row.phone + "-" + scope.row.number
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$t('message.hyklx')"
        prop="cardName"
        show-overflow-tooltip
        min-width="120"
      />
      <el-table-column
        align="center"
        :label="$t('message.czye')"
        show-overflow-tooltip
        prop="remainingMoney"
        min-width="100"
      />
      <el-table-column
        align="center"
        :label="$t('message.zsye')"
        show-overflow-tooltip
        prop="remainingGiveMoney"
        min-width="100"
      />
      <el-table-column
        align="center"
        :label="$t('message.hyczze')"
        show-overflow-tooltip
        prop="totalMoney"
        min-width="120"
      />
      <el-table-column
        align="center"
        :label="$t('message.hykxfze')"
        show-overflow-tooltip
        prop="totalConsume"
        min-width="120"
      />
      <el-table-column
        align="center"
        :label="$t('message.kmkh')"
        show-overflow-tooltip
        prop="chipNumber"
        min-width="130"
      />
      <el-table-column
        align="center"
        :label="$t('message.xpkh')"
        show-overflow-tooltip
        prop="entityNumber"
        min-width="130"
      />
      <!-- <el-table-column
        align="center"
        :label="$t('message.tc')"
        prop="mealNames"
        show-overflow-tooltip
        min-width="180"
      /> -->
      <el-table-column
        :label="$t('message.sfye')"
        prop="integral"
        min-width="100"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        :label="$t('message.createTime')"
        prop="createTime"
        min-width="160"
        align="center"
      />
      <el-table-column
        align="center"
        :label="$t('message.status')"
        width="80"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.status"
            v-preventReClick
            :active-value="'1'"
            :disabled="meta.indexOf('VipStatus') == -1"
            :inactive-value="'0'"
            @change="toConfigUpdate($event, scope.row.id, scope.row.status)"
          />
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('message.caozuo')"
        :width="$i18n.locale === 'ZH' ? 280 : 700"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <div class="flex-cc">
            <el-button
              v-if="meta.indexOf('VipChangeCard') > -1"
              v-preventReClick
              type="text"
              @click="motifyCardInfo(scope.row)"
              >{{ $t("message.gbstk") }}</el-button
            >
            <el-button
              v-if="meta.indexOf('IntegralCharge') > -1"
              v-preventReClick
              type="text"
              @click="toshowCz(scope.row)"
              >{{ $t("message.jftz") }}</el-button
            >
            <el-button
              v-if="meta.indexOf('MemberSyncUserToDev') > -1"
              v-preventReClick
              type="text"
              @click="tbry(scope.row.id)"
              >{{ $t("message.xfsb") }}</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <Paginations
      :total="totalCount"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />

    <el-dialog
      :title="$t('message.pldr')"
      :visible.sync="isShow"
      :close-on-click-modal="modalDialog"
      :close-on-press-escape="modalDialog"
      width="500px"
      center
    >
      <el-upload
        ref="excel-upload-input"
        :action="uploadFileUrl"
        :on-change="onChange"
        :data="uploadDatab"
        :auto-upload="true"
        accept=".xlsx, .xls"
        :on-success="handleSuccess"
        :on-error="handleError"
        :on-remove="removeFile"
        :file-list="fileList"
      >
        <el-button size="small" plain>{{ $t("message.xzwj") }}</el-button>
        <div slot="tip" class="el-upload__tip">
          <div class="mb10">{{ $t("message.znscbg") }}</div>
          <div>{{ $t("message.mbyqsm") }}</div>
          <div>{{ $t("message.hypldryq") }}</div>
          <div>{{ $t("message.hyyq1") }}</div>
          <div>{{ $t("message.hyyq2") }}</div>
          <div>{{ $t("message.hyyq3") }}</div>
          <div>{{ $t("message.hyyq4") }}</div>
          <div>{{ $t("message.hyyq5") }}</div>
          <div>
            {{ $t("message.hyyq6") }}
          </div>
          <div>{{ $t("message.hyyq7") }}</div>
        </div>
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button v-preventReClick @click="downLoad">{{
          $t("message.xzmb")
        }}</el-button>
        <el-button
          v-preventReClick
          type="primary"
          :loading="loadinga"
          @click="submit"
          >{{ $t("message.qr") }}</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      :title="$t('message.tcpldr')"
      :visible.sync="isShowb"
      :close-on-click-modal="modalDialog"
      :close-on-press-escape="modalDialog"
      width="500px"
      center
    >
      <el-upload
        ref="excel-upload-input"
        :action="uploadFileUrl"
        :on-change="onChange"
        :data="uploadData"
        :auto-upload="true"
        accept=".xlsx, .xls"
        :on-success="handleSuccessb"
        :on-error="handleErrorb"
        :on-remove="removeFileb"
        :file-list="fileListb"
      >
        <el-button size="small" plain>{{ $t("message.xzwj") }}</el-button>
        <div slot="tip" class="el-upload__tip">
          <div class="mb10">{{ $t("message.znscbg") }}</div>
          <div>{{ $t("message.mbyqsm") }}</div>
          <div>{{ $t("message.tcpldrsm") }}</div>
          <div>{{ $t("message.tcdr1") }}</div>
          <div>{{ $t("message.tcdr2") }}</div>
          <div>{{ $t("message.tcdr3") }}；</div>
          <div>{{ $t("message.tcdr4") }}</div>
          <div>{{ $t("message.tcdr5") }}</div>
          <div>{{ $t("message.tcdr6") }}</div>
        </div>
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button @click="downLoadb">{{ $t("message.xzmb") }}</el-button>
        <el-button v-preventReClick type="primary" @click="submitb">{{
          $t("message.qr")
        }}</el-button>
      </span>
    </el-dialog>
    <el-dialog
      :title="$t('message.drxxcw')"
      :visible.sync="isError"
      :close-on-click-modal="modalDialog"
      :close-on-press-escape="modalDialog"
      width="30%"
      center
    >
      <div v-for="(item, index) in errList" :key="index">{{ item }}</div>
      <span slot="footer" class="dialog-footer">
        <el-button v-preventReClick type="primary" @click="close">{{
          $t("message.qr")
        }}</el-button>
      </span>
    </el-dialog>
    <el-dialog
      :title="$t('message.gbstk')"
      width="480px"
      :visible.sync="showChange"
      :close-on-click-modal="modalDialog"
      :close-on-press-escape="modalDialog"
    >
      <el-form :model="vipInfo" label-suffix="：" label-width="auto">
        <el-form-item :label="$t('message.kmkh')" prop="chipNumber">
          <el-input
            v-model="vipInfo.chipNumber"
            class="w200"
            :placeholder="$t('message.qsr') + $t('message.kmkh')"
          />
        </el-form-item>
        <el-form-item :label="$t('message.xpkh')" prop="entityNumber">
          <el-input
            v-model="vipInfo.entityNumber"
            class="w200"
            :placeholder="$t('message.qsr') + $t('message.xpkh')"
          />
          <el-button
            class="viplist-btn-style"
            type="primary"
            @click="getCardNum"
            >{{ $t("message.caji") }}</el-button
          >
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-if="vipInfo.entityNumber"
          v-preventReClick
          type="danger"
          @click="unbindEntityNumber"
          >{{ $t("message.jieban") }}</el-button
        >
        <el-button @click="cancelMotify">{{ $t("message.qx") }}</el-button>
        <el-button
          v-preventReClick
          type="primary"
          :loading="loadingb"
          @click="confirmMotify"
          >{{ $t("message.qr") }}</el-button
        >
      </div>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="modalDialog"
      :close-on-press-escape="modalDialog"
      :title="$t('message.jftz')"
      :visible.sync="showCz"
      width="500px"
    >
      <el-form label-width="auto" label-suffix="：">
        <el-form-item :label="$t('message.sfye')">
          <span>{{ integralForm.ye }}</span>
        </el-form-item>
        <el-form-item :label="$t('message.tzfs')">
          <el-radio v-model="integralForm.type" label="0">{{
            $t("message.zj")
          }}</el-radio>
          <el-radio v-model="integralForm.type" label="1">{{
            $t("message.js")
          }}</el-radio>
        </el-form-item>
        <el-form-item :label="$t('message.jifen')">
          <el-input
            v-model="integralForm.integral"
            onkeyup="this.value=this.value.replace(/\D/g,'')"
            onafterpaste="this.value=this.value.replace(/\D/g,'')"
            oninput="if(value<0) { value = ''}"
            :placeholder="$t('message.qsr') + $t('message.jifen')"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showCz = false">{{ $t("message.qx") }}</el-button>
        <el-button v-preventReClick type="primary" @click="confirmCz">{{
          $t("message.qr")
        }}</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="modalDialog"
      :close-on-press-escape="modalDialog"
      :title="$t('message.bz')"
      :visible.sync="showMark"
      width="500px"
      :before-close="closeMark"
    >
      <el-form ref="ruleForm" :model="param" :rules="rules" label-suffix="：">
        <el-form-item
          :label="$t('message.bz')"
          label-width="auto"
          prop="remark"
        >
          <el-input
            v-model="param.remark"
            :placeholder="$t('message.qsr') + $t('message.bz')"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeMark">{{ $t("message.qx") }}</el-button>
        <el-button v-preventReClick type="primary" @click="confirmRemark">{{
          $t("message.qr")
        }}</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="modalDialog"
      :close-on-press-escape="modalDialog"
      :title="$t('message.jbq')"
      :visible.sync="isShowTag"
      width="520px"
    >
      <div class="mb20">
        <el-radio v-model="tagParam.type" label="0"
          >{{ $t("message.yxzdq") }}{{ selMember.length
          }}{{ $t("message.tsj") }}</el-radio
        >
      </div>
      <div class="mb20">
        <el-radio v-model="tagParam.type" label="1"
          >{{ $t("message.yxzsxxqbd") }}{{ totalCount
          }}{{ $t("message.tsj") }}</el-radio
        >
      </div>
      <div v-if="!setTagFlag">
        <el-select
          v-model="tagParam.memberTagIds"
          class="ml20 w300"
          multiple
          filterable
          collapse-tags
          :placeholder="$t('message.qxzbqzcdx')"
        >
          <el-option
            v-for="item in tagOptions"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
        <el-button class="ml10" @click="handleAddTagOne">{{
          $t("message.tjbq")
        }}</el-button>
      </div>
      <template v-if="setTagFlag">
        <el-input
          ref="TagInputRef"
          v-model="tagParam.name"
          :placeholder="$t('message.qsr') + $t('message.bqmc')"
          class="w200 ml20"
        />
        <el-button class="ml10" @click="setTagFlag = false">{{
          $t("message.qx")
        }}</el-button>
        <el-button
          v-preventReClick
          class="ml10"
          type="primary"
          @click="suAddTagOnesuAddTagOne"
          >{{ $t("message.baocun") }}</el-button
        >
      </template>
      <div slot="footer" class="dialog-footer">
        <el-button @click="isShowTag = false">{{ $t("message.qx") }}</el-button>
        <el-button
          v-preventReClick
          type="primary"
          :loading="tagLoading"
          @click="onSubTag"
          >{{ $t("message.qr") }}</el-button
        >
      </div>
    </el-dialog>
    <MemberAdd
      v-if="isShowMemberAdd"
      ref="MemberAddRef"
      @success="getList(1)"
      @close="isShowMemberAdd = false"
      @submit="toVipAdd"
    />
    <VipAdd
      v-if="isShowVipAdd"
      ref="VipAddRef"
      @register="memberAdd"
      @success="vipAddSuccess"
      @close="isShowVipAdd = false"
    />
    <VipRecharge
      v-if="isShowVipRecharge"
      ref="VipRechargeRef"
      @success="getList()"
      @close="isShowVipRecharge = false"
    />
  </div>
</template>
<script>
import {
  uploadFile,
  memberList,
  memberListEx,
  cardList,
  memberStatus,
  insertMember,
  insertMemberMoudle,
  memberBindEntityNumber,
  integralCharge,
  syncUserToDev,
  collectCard,
  importPackage,
  importMoudle,
  memberTagAbleList,
  memberTagAdd,
  memberTagBind,
} from "@/api";
import { parseTime } from "@/utils/index";
import store from "@/store";
import QueryForm from "@/components/QueryForm";
import MemberAdd from "@/views/vipList/memberAdd/index.vue";
import VipAdd from "@/views/vipCard/vipAdd/index.vue";
import VipRecharge from "@/views/vipList/vipRecharge/index.vue";
import { queryFormConfig } from "./config";
export default {
  name: "VipList",
  components: {
    QueryForm,
    MemberAdd,
    VipAdd,
    VipRecharge,
  },
  props: {
    meta: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      exLoading: false,
      selMember: [],
      isShowTag: false,
      tagParam: {
        type: "0",
      },
      tagOptions: [],
      setTagFlag: false,
      tagLoading: false,

      isShowMemberAdd: false,
      isShowVipAdd: false,
      isShowVipRecharge: false,
      queryFormConfig,
      modalDialog: store.getters.dialog,
      uploadFileUrl: uploadFile,
      totalCount: 0,
      list: [],
      integralForm: {},
      listLoading: false,
      loading: false,
      isShow: false,
      isShowb: false,
      fileList: [],
      fileListb: [],
      excelPath: "",
      fileUrl: "",
      uploadData: {
        folder: "PUBLIC_IMG",
        type: "",
      },
      uploadDatab: {
        folder: "MEALS_IMG",
      },
      isError: false,
      showChange: false,
      showMark: false,
      loadinga: false,
      loadingb: false,
      param: {},
      memberStatus: "",
      vipInfo: {},
      errList: [],
      pagination: {
        page: 1,
        rows: 10,
      },
      filters: {},
      vipType: [],
      showCz: false,
      jifen: "",
      memberId: "",
      tjList: [],
      rules: {
        remark: [
          {
            required: true,
            message: this.$t("message.qsr") + this.$t("message.bz"),
            trigger: "blur",
          },
        ],
      },
      smTip: "",
    };
  },
  created() {
    this.getCardList();
    this.getList(1);
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.table.doLayout();
    });
  },
  activated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout();
    });
  },
  methods: {
    getMemberTag() {
      memberTagAbleList({ param: {} }).then((res) => {
        this.tagOptions = res.recordList;
      });
    },
    handleSelectionChange(val) {
      this.selMember = val;
    },
    handleAddTag() {
      // const { selMember } = this
      this.isShowTag = true;
      this.setTagFlag = false;
      this.tagParam = {
        type: "0",
      };
      this.getMemberTag();
    },
    handleAddTagOne() {
      this.setTagFlag = true;
      this.$nextTick(() => {
        this.$refs.TagInputRef.focus();
      });
      this.$set(this.tagParam, "name", "");
    },
    suAddTagOnesuAddTagOne() {
      const { tagParam } = this;
      if (!tagParam.name) {
        return this.$message.warning(this.$t("message.qxsrbqmc"));
      }
      memberTagAdd({ param: { name: tagParam.name } }).then((res) => {
        this.$message.success(this.$t("message.bqtjcg"));
        this.getMemberTag();
        this.setTagFlag = false;
      });
    },
    onSubTag() {
      const { selMember, filters } = this;
      let { tagParam } = this;
      if (!tagParam.memberTagIds || tagParam.memberTagIds.length === 0) {
        return this.$message.warning(this.$t("message.qxxzytjdbq"));
      }
      if (tagParam.type === "0") {
        if (selMember.length === 0) {
          return this.$message.warning(this.$t("message.qxxzhy"));
        }
        tagParam.memberIds = selMember.map((i) => i.id);
      } else {
        tagParam = { ...tagParam, ...filters, memberIds: null };
      }
      this.tagLoading = true;
      memberTagBind({ param: tagParam }).then(
        (res) => {
          this.tagLoading = false;
          this.$message.success(this.$t("message.hybqtjcg"));
          this.isShowTag = false;
          this.selMember = [];
          this.getList();
        },
        () => {
          this.tagLoading = false;
        }
      );
    },
    handleSizeChange(value) {
      this.pagination.rows = value;
      this.getList(1);
    },
    vipAddSuccess() {
      this.isShowVipAdd = false;
      this.getList();
    },
    getimportPackage() {
      importPackage({ param: { excelPath: this.excelPath } }).then((res) => {
        if (res.errorCode === "000000") {
          this.$message.success(this.$t("message.drcg"));
          this.getList(1);
        }
      });
    },
    onChange(file, list) {
      if (list.length > 1 && file.status !== "fail") {
        list.splice(0, 1);
      } else if (file.status === "fail") {
        list.splice(0, 1);
      }
    },
    tbry(userId) {
      syncUserToDev({
        param: {
          type: "0",
          userType: "1",
          userId,
        },
      })
        .then((res) => {
          if (res.errorCode === "000000") {
            this.$message.success(this.$t("message.tbcg"));
            this.getList();
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    toshowCz(row) {
      this.integralForm = {
        memberId: row.id,
        type: "1",
        ye: row.integral,
      };
      this.showCz = true;
    },
    toshowDetail(id) {
      this.$router.push({ name: "VipDetails", query: { id: id } });
    },
    confirmCz() {
      const { integralForm } = this;
      if (!integralForm.integral) {
        return this.$message.error(
          this.$t("message.qsr") + this.$t("message.jifen")
        );
      }
      integralCharge({
        param: { ...integralForm },
      }).then((res) => {
        if (res.errorCode === "000000") {
          this.$message.success(this.$t("message.jftzcg"));
          this.showCz = false;
          this.getList();
        }
      });
    },
    setMemberStatus(id, status) {
      this.showMark = true;
      this.$set(this.param, "remark", "");
      this.memberId = id;
      this.memberStatus = status;
    },
    confirmRemark() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          memberStatus({
            param: {
              id: this.memberId,
              status: this.memberStatus === "1" ? "0" : "1",
              note: this.param.remark,
            },
          }).then((res) => {
            if (res.errorCode === "000000") {
              if (this.memberStatus === "0") {
                this.$message.success(this.$t("message.qycg"));
              } else {
                this.$message.success(this.$t("message.jycg"));
              }
              this.showMark = false;
              this.getList(this.pagination.page);
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    closeMark() {
      const arr = this.list;
      arr.forEach((e) => {
        if (e.id === this.memberId) {
          e.status = this.memberStatus;
        }
      });
      this.list = arr;
      this.showMark = false;
    },
    toConfigUpdate(e, id, status) {
      this.setMemberStatus(id, status === "1" ? "0" : "1");
    },
    toVipAdd(info) {
      this.isShowVipAdd = true;
      this.$nextTick(() => {
        this.$refs.VipAddRef.isShow = true;
        if (info) {
          this.$refs.VipAddRef.memberSelect(info);
        }
      });
    },
    memberAdd(value) {
      // this.$router.push({ name: 'MemberAdd' })
      this.isShowMemberAdd = true;
      this.$nextTick(() => {
        this.$refs.MemberAddRef.param.phone = value || "";
        this.$refs.MemberAddRef.isShowMember = true;
      });
    },
    memberRecharge() {
      this.isShowVipRecharge = true;
      this.$nextTick(() => {
        this.$refs.VipRechargeRef.isShow = true;
      });
    },
    inBatch() {
      this.isShow = true;
    },
    downLoad() {
      insertMemberMoudle({ param: {} })
        .then((res) => {
          if (res.errorCode === "000000") {
            if (window.Android) {
              Android.downloadFile(res.record);
              return;
            }
            window.open(res.record, "_blank");
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    downLoadb() {
      importMoudle({ param: {} })
        .then((res) => {
          if (res.errorCode === "000000") {
            if (window.Android) {
              Android.downloadFile(res.record);
              return;
            }
            window.open(res.record, "_blank");
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    submitb() {
      if (this.fileListb.length === 0) {
        this.$message.error(this.$t("message.qxxzwj"));
        return;
      }
      // excelPath
      const venueId = sessionStorage.getItem("venueId");
      this.isShowb = false;
      importPackage({
        param: { excelPath: this.excelPath, venueId },
        userId: sessionStorage.getItem("userId"),
      })
        .then((res) => {
          if (res.errorCode === "000000") {
            this.$message.success(this.$t("message.pldrcg"));
            this.getList(1);
            this.fileListb = [];
            this.excelPath = "";
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    submit() {
      // console.log('提交', this.fileList)
      if (this.fileUrl.length === 0) {
        this.$message.error(this.$t("message.qxxzwj"));
        return;
      }
      // excelPath
      const venueId = sessionStorage.getItem("venueId");
      this.loadinga = true;
      insertMember({
        param: { excelPath: this.fileUrl, venueId },
        userId: sessionStorage.getItem("userId"),
      })
        .then((res) => {
          this.isShow = false;
          this.loadinga = false;
          if (res.errorCode === "000000") {
            this.$message.success(this.$t("message.pldrcg"));
            this.getList(1);
            this.fileList = [];
            if (res.record.errList.length) {
              this.errList = res.record.errList;
              this.isError = true;
            }
          }
        })
        .catch((err) => {
          this.loadinga = false;
          console.log(err);
        });
    },
    close() {
      this.isError = false;
    },
    // 文件超出个数限制时的钩子
    exceedFile(files, fileList) {
      this.$notify.warning({
        title: this.$t("message.jingao"),
        message:
          this.$t("message.znxzygwj") +
          ` ${files.length + fileList.length} ` +
          this.$t("message.gei"),
      });
    },
    // 文件状态改变时的钩子
    fileChange(file, fileList) {
      console.log("change", file, fileList);
      // const formDate = new FormData()
      // formDate.append('file', file)
      // Axios.post(this.uploadFileUrl, formDate).then(res => {
      //   console.log(res)
      // })
    },
    // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
    beforeUploadFile(file) {
      console.log("before upload");
      // const extension = file.name.substring(file.name.lastIndexOf('.') + 1)
      const size = file.size / 1024 / 1024;
      if (size > 10) {
        this.$notify.warning({
          title: this.$t("message.jingao"),
          message: this.$t("message.wjdabndy10"),
        });
      }
    },
    // 文件上传成功时的钩子
    handleSuccess(res, file, fileList) {
      this.fileList = fileList;
      this.fileUrl = file.response.showUrl;
    },
    // 文件上传失败时的钩子
    handleError(err, file, fileList) {
      this.fileList = [];
      this.fileUrl = "";
      this.$notify.error({
        title: this.$t("message.cw"),
        message: this.$t("message.wjscsb"),
      });
      console.log(err, file, fileList);
    },
    // 文件移除
    removeFile(file, fileList) {
      console.log("移除");
      this.fileUrl = "";
    },
    handleSuccessb(res, file, fileList) {
      // console.log('成功', fileList)
      this.fileListb = fileList;
      this.excelPath = file.response.showUrl;
    },
    // 文件上传失败时的钩子
    handleErrorb(err, file, fileList) {
      console.log(this.$t("message.cw"));
      this.fileListb = [];
      this.excelPath = "";
      this.$notify.error({
        title: this.$t("message.cw"),
        message: this.$t("message.wjscsb"),
      });
      console.log(err, file, fileList);
    },
    // 文件移除
    removeFileb(file, fileList) {
      this.fileListb = [];
      this.excelPath = "";
    },
    handleEx() {
      // 获取会员列表
      this.exLoading = true;
      const { filters } = this;
      memberListEx({
        param: { ...filters, needCensus: "1" },
      })
        .then((res) => {
          this.exLoading = false;
          if (res.errorCode === "000000") {
            if (window.Android) {
              Android.downloadFile(res.record.showUrl);
              return;
            }
            window.open(res.record.showUrl, "_blank");
          }
        })
        .catch((err) => {
          console.log(err);
          this.exLoading = false;
        });
    },
    getList(page) {
      // 获取会员列表
      this.listLoading = true;
      const { filters, pagination } = this;
      if (page) {
        pagination.page = page;
        this.pagination.page = page;
      }
      if (pagination.page === 1) {
        pagination.firstQueryTime = parseTime(new Date());
      }
      memberList({
        pagination,
        param: { ...filters, needCensus: "1" },
      })
        .then((res) => {
          this.listLoading = false;
          if (res.errorCode === "000000") {
            this.list = res.recordList;
            this.totalCount = res.totalCount;
            const tjList = res.data.censusList;
            if (tjList) {
              let smTip = "";
              tjList.forEach((s) => {
                smTip = smTip + s.tip + "<br />";
              });
              this.tjList = tjList;
              this.smTip = smTip;
            }
            if (res.recordList.length === 0) {
              this.$message.error(this.$t("message.wcxdhy"));
            }
          }
        })
        .catch((err) => {
          console.log(err);
          this.listLoading = false;
        });
    },
    getCardList() {
      // 获取卡类型列表
      cardList({
        pagination: {
          page: 1,
          rows: 1000,
          firstQueryTime: this.filters.firstQueryTime,
        },
        param: {
          cardName: null,
          isnormal: null,
          channel: null,
          type: "1",
        },
      })
        .then((res) => {
          if (res.errorCode === "000000") {
            this.vipType = res.recordList;
            const arrb = res.recordList;
            arrb.forEach((e) => {
              e.label = e.cardName;
              e.value = e.id;
            });
            this.queryFormConfig.formItems[4].options = arrb;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    motifyCardInfo(item) {
      item = JSON.stringify(item);
      item = JSON.parse(item);
      this.vipInfo = item;
      this.showChange = true;
    },
    cancelMotify() {
      this.vipInfo = {};
      this.showChange = false;
    },
    unbindEntityNumber() {
      memberBindEntityNumber({
        param: {
          memberId: this.vipInfo.id,
          type: "1",
        },
      })
        .then((res) => {
          this.showChange = false;
          if (res.errorCode !== "000000") return;
          this.$message.success(this.$t("message.jbcg"));
          this.getList(1);
        })
        .catch(() => {});
    },
    confirmMotify() {
      // 修改实体卡号
      if (!this.vipInfo.entityNumber && !this.vipInfo.chipNumber) {
        this.$message.warning(this.$t("message.xphkhbntswk"));
        return;
      }
      this.loadingb = true;
      memberBindEntityNumber({
        param: {
          entityNumber: this.vipInfo.entityNumber,
          chipNumber: this.vipInfo.chipNumber,
          memberId: this.vipInfo.id,
          type: "0",
        },
      })
        .then((res) => {
          if (res.errorCode === "000000") {
            this.loadingb = false;
            this.showChange = false;
            this.$message.success(this.$t("message.gbcg2"));
            this.getList();
          }
        })
        .catch(() => {
          this.loadingb = false;
        });
    },
    // 清空
    clear() {
      this.filters = {};
      this.getList(1);
    },
    getCardNum() {
      collectCard({
        param: {
          venueId: sessionStorage.getItem("venueId"),
          shopId: localStorage.getItem("shopId"),
        },
      }).then((res) => {
        if (res.errorCode === "000000") {
          this.$set(this.vipInfo, "entityNumber", res.record.card);
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.vip-info {
  display: flex;
  justify-content: center;
  .name-phone {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: left;
    margin-left: 10px;
  }
}
.viplist-btn-style {
  margin-left: 20px;
}
</style>
